package com.comsoftstar.nt5s.deviceManager.utils;

import android.content.Context;
import android.os.Handler;
import android.view.Gravity;
import android.widget.Toast;

public class MessagePop {
    /**
     * 弹出Toast消息
     *
     * @param msg
     */
    private static Toast mToast;
    private static Handler mhandler = new Handler();
    private static Runnable r = new Runnable() {
        public void run() {
            mToast.cancel();
        }
    };

    public static void ToastMessage(Context context, String msg) {
        mhandler.removeCallbacks(r);
        if (null != mToast) {
            mToast.setText(msg);
        } else {
            mToast = Toast.makeText(context, msg, Toast.LENGTH_LONG);
        }
        mhandler.postDelayed(r, 5000);
        mToast.show();
    }

    public static void ToastMessage(Context cont, int msg) {
        Toast.makeText(cont, msg, Toast.LENGTH_SHORT).show();
    }

    public static void ToastMessage(Context cont, String msg, int time) {
        Toast.makeText(cont, msg, time).show();
    }

    public static void ToastMessage(Context cont, int msg, int time) {
        Toast.makeText(cont, msg, time).show();
    }

    public static void ToastMessdageTop(Context cont, String msg) {
        Toast toast = Toast.makeText(cont, msg, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.TOP, 0, 120);
        toast.show();
    }
}
